home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / simula / books / books.lha / kirkerud / encrypt.sim < prev    next >
Text File  |  1993-08-16  |  987b  |  33 lines

  1. !  Example 3.8;
  2.  
  3. begin 
  4.  
  5.   character char_in_word;
  6.   integer   char_number,    ! This is a declaration of a variable;
  7.           crypt_add = 13; ! This is  a declaration of a constant;
  8.  
  9.   outtext( "Write a word to be encrypted > "); breakoutimage;
  10.   inimage;
  11.   char_in_word := inchar;
  12.  
  13.   while letter(char_in_word) do
  14.     begin
  15.       char_number := rank(char_in_word) + crypt_add;
  16.       if char_in_word le 'Z'
  17.                !  Then char_in_word  is an upper case letter;
  18.           and char_number > rank('Z')
  19.                !  and the encrypted letter is after 'Z';
  20.           then char_number := char_number - rank('Z') + rank('A') - 1
  21.                !  the encrypted letter is put after 'A';
  22.       else if char_number > rank('z') then
  23.         char_number := char_number - rank('z') + rank('a') - 1;
  24.                !  Correspondingly for lower case letters;
  25.       outchar(char(char_number));
  26.       char_in_word := inchar;
  27.     end;
  28.  
  29.   outtext(" is the encrypted version!");
  30.   outimage;
  31.  
  32. end
  33.